from django.db import models


# Create your models here.
class Person(models.Model):
    GENDER_CHOICES = [("男", "Male"), ("女", "Female")]
    name = models.CharField(max_length=20, unique=True)
    age = models.IntegerField(default=18)
    gender = models.CharField(max_length=20, choices=GENDER_CHOICES)


class Address(models.Model):
    person = models.OneToOneField(Person, on_delete=models.CASCADE, related_name='address')
    city = models.CharField(max_length=20)
    town = models.CharField(max_length=20)
    village = models.CharField(max_length=20)
    detailaddress = models.CharField(max_length=20)


class Author(models.Model):
    GENDER_CHOICES = [("F", "女"), ("M", "男")]

    name = models.CharField(max_length=50, unique=True)
    age = models.IntegerField()
    gender = models.CharField(max_length=1, choices=GENDER_CHOICES)


class book(models.Model):
    name = models.CharField(max_length=50)
    price = models.DecimalField(max_digits=5, decimal_places=2)
    publisher = models.CharField(max_length=50, null=False)
    author = models.ForeignKey(Author, on_delete=models.CASCADE, related_name='book')
